//package com.Stash.Config;
//
//import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
//import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//
//public class RedisConfig {
//        @Value("localhost")
//        private String host;
//        @Value("6379")
//        private Integer port;
//
//        //@Value("${redis.password}")
//        //private String password;
//
//        @Value("10")
//        private Integer maxActive;
//        @Value("5")
//        private Integer minIdle;
//        @Value("1")
//        private Integer maxIdle;
//        @Value("3000")
//        private Integer maxWait;
//
//        //获取RedisTemplate
//        @Bean
//        public RedisTemplate getRedisTemplate(
//                @Autowired RedisConnectionFactory redisConnectionFactory) {
//            RedisTemplate redisTemplate = new RedisTemplate();
//            redisTemplate.setConnectionFactory(redisConnectionFactory);
//
//            //设置 Redis 生成的key的序列化器，这个很重要
//            //RedisTemplate 默认使用 jdk 序列化器，会出现 Redis 的 key 保存成乱码的情况
//            //一般情况下 Redis 的 key 都使用字符串，
//            //为了保障在任何情况下使用正常，最好使用 StringRedisSerializer 对 key 进行序列化
////            RedisSerializer stringSerializer = new StringRedisSerializer();
////            redisTemplate.setKeySerializer(stringSerializer);
////            redisTemplate.setHashKeySerializer(stringSerializer);
//            return redisTemplate;
//        }
//
//        //获取 Redis 连接工厂
//        @Bean
//        public RedisConnectionFactory getRedisConnectionFactory(
//                @Autowired RedisStandaloneConfiguration redisStandaloneConfiguration,
//                @Autowired GenericObjectPoolConfig genericObjectPoolConfig) {
//            JedisClientConfiguration.JedisPoolingClientConfigurationBuilder builder
//                    = (JedisClientConfiguration.JedisPoolingClientConfigurationBuilder)
//                    JedisClientConfiguration.builder();
//            builder.poolConfig(genericObjectPoolConfig);
//            JedisConnectionFactory jedisConnectionFactory =
//                    new JedisConnectionFactory(redisStandaloneConfiguration, builder.build());
//            return jedisConnectionFactory;
//        }
//
//        //获取 Spring 提供的 Redis 连接池信息
//        @Bean
//        public GenericObjectPoolConfig getGenericObjectPoolConfig() {
//            GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
//            genericObjectPoolConfig.setMaxTotal(maxActive);
//            genericObjectPoolConfig.setMinIdle(minIdle);
//            genericObjectPoolConfig.setMaxIdle(maxIdle);
//            genericObjectPoolConfig.setMaxWaitMillis(maxWait);
//            return genericObjectPoolConfig;
//        }
//
//        //获取 Redis 配置对象
//        @Bean
//        public RedisStandaloneConfiguration getRedisStandaloneConfiguration() {
//            RedisStandaloneConfiguration redisStandaloneConfiguration =
//                    new RedisStandaloneConfiguration();
//            redisStandaloneConfiguration.setHostName(host);
//            redisStandaloneConfiguration.setPort(port);
//            //redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
//            return redisStandaloneConfiguration;
//        }
//
//}
